package com.homepage.service;

import com.homepage.domain.PartnerLogo;
import com.homepage.repository.PartnerLogoRepository;
import com.homepage.service.dto.PartnerLogoDTO;
import com.homepage.service.mapper.PartnerLogoMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link PartnerLogo}.
 */
@Service
@Transactional
public class PartnerLogoService {

    private final Logger log = LoggerFactory.getLogger(PartnerLogoService.class);

    private final PartnerLogoRepository partnerLogoRepository;

    private final PartnerLogoMapper partnerLogoMapper;

    public PartnerLogoService(PartnerLogoRepository partnerLogoRepository, PartnerLogoMapper partnerLogoMapper) {
        this.partnerLogoRepository = partnerLogoRepository;
        this.partnerLogoMapper = partnerLogoMapper;
    }

    /**
     * Save a partnerLogo.
     *
     * @param partnerLogoDTO the entity to save.
     * @return the persisted entity.
     */
    public PartnerLogoDTO save(PartnerLogoDTO partnerLogoDTO) {
        log.debug("Request to save PartnerLogo : {}", partnerLogoDTO);
        PartnerLogo partnerLogo = partnerLogoMapper.toEntity(partnerLogoDTO);
        partnerLogo = partnerLogoRepository.save(partnerLogo);
        return partnerLogoMapper.toDto(partnerLogo);
    }

    /**
     * Partially update a partnerLogo.
     *
     * @param partnerLogoDTO the entity to update partially.
     * @return the persisted entity.
     */
    public Optional<PartnerLogoDTO> partialUpdate(PartnerLogoDTO partnerLogoDTO) {
        log.debug("Request to partially update PartnerLogo : {}", partnerLogoDTO);

        return partnerLogoRepository
            .findById(partnerLogoDTO.getId())
            .map(existingPartnerLogo -> {
                partnerLogoMapper.partialUpdate(existingPartnerLogo, partnerLogoDTO);

                return existingPartnerLogo;
            })
            .map(partnerLogoRepository::save)
            .map(partnerLogoMapper::toDto);
    }

    /**
     * Get all the partnerLogos.
     *
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public List<PartnerLogoDTO> findAll() {
        log.debug("Request to get all PartnerLogos");
        return partnerLogoRepository.findAll().stream().map(partnerLogoMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     * Get one partnerLogo by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<PartnerLogoDTO> findOne(Long id) {
        log.debug("Request to get PartnerLogo : {}", id);
        return partnerLogoRepository.findById(id).map(partnerLogoMapper::toDto);
    }

    @Transactional(readOnly = true)
    public Optional<PartnerLogoDTO> findOneByPartnerId(Long id) {
        log.debug("Request to get PartnerLogo : {}", id);
        return partnerLogoRepository.findPartnerLogoByPartnerId(id).map(partnerLogoMapper::toDto);
    }

    /**
     * Delete the partnerLogo by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete PartnerLogo : {}", id);
        partnerLogoRepository.deleteById(id);
    }
}
